<!DOCTYPE html>
<html lang="zh-CN">
<head>

<#include "bases/global_style.ftl">
<#include "bases/global_js.ftl">
<#include "bases/combo.ftl">

	<style type="text/css">
         label{width: 70px;text-align: left;}
         table 
		{ 
			margin-left: auto; 
			margin-right: auto; 
		} 
    </style>
    
	<script>
		var curent_page=${currentpage};

		//套餐显示详情
		function showComboDetails(){
			 $(".am-comboBtn").on("mouseover",function(event){
				var thisItem=$(this);
				  //鼠标悬浮
				  thisItem.next().find(".am-comboContent").css("display","block");
				  $(".am-obligate").css("display","block");
			});
			$(".am-comboBtn").on("mouseout",function(event){
				var thisItem=$(this);
				  //鼠标离开
				  thisItem.next().find(".am-comboContent").css("display","none");
				  $(".am-obligate").css("display","none");
				  $(".am-comboDetails div").empty();
			});
		}

		function showInfo(id)
		{
			$.ajax({
				type : "POST",
				url : CONTEXT+'/get_cartype?companyid='+id,
				dataType : "json",  
	      	    cache : false,  
	      	    async : false,
	      	  	success : function(data) {
		      	  	if(data.length==0){
		      	  		$(".am-comboDetails").append("<div><span>该公司未添加车型</span></div>");
			      	}else{
			      		for(var i=0;i<data.length;i++){
				      	  	$.ajax({
					      	  	type : "POST",
					      	  	url : CONTEXT+'/get_postage_by_id?cartype='+data[i].id+'&accountid='+id,
					      	  	dataType : "json",  
					      	    cache : false,  
					      	    async : false,
					      	  	success : function(d) {
						      	  	if(d.length==0){
						      	  		$(".am-comboDetails").append("<div><span>"+data[i].name+"</span><span>未匹配</span></div>");
							      	}else if(d[0].type==1){
							      		$(".am-comboDetails").append("<div><span>"+data[i].name+"</span><span>"+d[0].name+"</span></div>");
								    }else{
								    	$(".am-comboDetails").append("<div><span>"+data[i].name+"</span><span>"+d[0].value+"</span></div>");
									}
						      	  	showComboDetails();
					      	  	}
					      	});
				      	}
				    }
	      	  	}
			});
		}
 
    	var addformv;
    	jQuery(document).ready(function()
    	{
    		var optInit = getOptionsFromForm();
    		$("#Pagination").pagination(${totalRecord}, optInit);
    		App.init();
    		combox("addProvince","Province",null,null,false);
            combox('addCity','City',$("#addProvince").val(),null,false);
 
    		combox("addProvince","Province",null);
            combox('addCity','City',$("#addProvince").val());
 
            addformv=$("#addForm").validate({
                debug:true //只验证不提交表单
            });
            
    		//个人公司切换
    		$(".role1Btn").change(function() {
    				var $selectedvalue = $("input[name='type']:checked").val();
    				if ($selectedvalue == 0) {
        				$(".private").css("display","");
        				$(".company").css("display","none");
        				$("input[name=self]").val(["1"]);
        				$(".notself").css("display","none");
    				}else {
    					$(".private").css("display","none");
        				$(".company").css("display","");
    				}
    		});
    		//自有非自有切换
    		$(".carBtn").change(function() {
        		var selectedvalue = $("input[name='self']:checked").val();
        		if(selectedvalue == 1) {//自有
        			$(".self").css("display","");
    				$(".notself").css("display","none");
    				$("#addCartype").removeAttr("disabled");
            	}else{//非自有
            		$(".self").css("display","none");
    				$(".notself").css("display","");
                }
        	});
    	});

	   	//银行账号验证
	   	jQuery.validator.addMethod("banknum", function (value, element) {
		   	var banknum = /^(\d{4}[\s\-]?){4,5}\d{3}$/g;
		   	return this.optional(element) || (banknum.test(value));
	   	}, "银行卡号格式不正确");
		
		//车牌号验证
		jQuery.validator.addMethod("plate", function (value, element) {
			var plate = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
			return this.optional(element) || (plate.test(value));
		}, "车牌号格式不正确");

	   	function addEntity()
	   	{
	   		addformv.form();
	   		if(addformv.valid()){
	   			var a ;
                var nowtime = new Date();
                var strtemp = ""+nowtime.getHours()+nowtime.getMinutes()+nowtime.getSeconds()+nowtime.getMilliseconds();
                a=strtemp;

    	          $.getJSON("${base}/add_account_general/" + a+
                          "?"+$("#addForm").serialize()
                  ,
                  function(data)
                  {
                      if(data ==1) {
                          alert("添加成功！");
                          location.href='${base}/account_user_manage';
                      }
                      else if(data ==-11)
                          alert("未知错误！");
                  });
	   		}
		}

    	function pageselectCallback(page_index, jq)
        {
            if (curent_page != page_index)
            {
                $("#currentpage").val(page_index);
                $("#searchform").submit();
                return true;
            }
        }

    	function showPopup(div) 
        {//弹出层
            var backDiv = document.getElementById("backDiv");
            backDiv.style.top = "0%";//设置弹出层距离上边界的距离
            backDiv.style.left = "0%";//设置弹出层距离左边界的距离
            backDiv.style.width = "100%";//设置弹出层的宽度
            backDiv.style.height = "100%";//设置弹出层的高度
            backDiv.style.visibility = "visible";

            var addDiv = document.getElementById(div);
            addDiv.style.top = "10%";//设置弹出层距离上边界的距离
            addDiv.style.left = "30%";//设置弹出层距离左边界的距离
            addDiv.style.width = "40%";//设置弹出层的宽度
            addDiv.style.height = "auto";//设置弹出层的高度
            addDiv.style.visibility = "visible";
 
        }

    	function hideEditTable() 
        {//关闭层
        	addformv.resetForm();
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var addDiv = document.getElementById("addDiv");
            addDiv.style.visibility = "hidden";

        }

    	function hidePopup() 
        {//关闭层
 
            // resetLabel();
            var backDiv = document.getElementById("backDiv");
            backDiv.style.visibility = "hidden";

            var addDiv = document.getElementById("addDiv");
            addDiv.style.visibility = "hidden";
        }

    	function allDivHide() 
        {
            hidePopup();
            hideEditTable();
        }

        function fresh()
        {
        	allDivHide();
        }
	</script>
</head>
<!-- END HEAD -->
<!-- BEGIN BODY -->
<body>
	<!-- END HEADER -->
	
	<div id="backDiv" onclick="allDivHide()" style="position: absolute;visibility: hidden;position:fixed;overflow: hidden;solid: #000000;background-color: #000000;padding: 1px;z-index: 99;filter:alpha(opacity=50);opacity: 0.5;"></div>
	
	<!-- 新增账户 -->
	<div id="addDiv" class="row-fluid" style="position: absolute;visibility: hidden;overflow: hidden;padding: 1px;z-index: 100;background-color: #FFFFFF;">
		<div class="span12">
			<div class="portlet box green" style="padding: 0px;margin:0px;">
				<div class="portlet-title">
                    <div class="caption"><i class="fa fa-edit"></i>新增账户</div>
                    <a href="javascript:allDivHide();" class="remove"></a>
                </div>
                
                <div class="portlet-body flip-scroll">
                	<form id="addForm" action="<@spring.url '/account_user_general'></@spring.url>" method="POST">
                		<table class="table-bordered table-striped table-condensed flip-content">
                			<tbody role="alert" aria-live="polite" aria-relevant="all">
                				<tr class="even">
                					<td style="text-align: right;">账户类型</td>
                					<td class="center">
                						<label class="radio-inline">
				  							<input type="radio" name="type" class="role1Btn" id="radio1" value="0" checked="checked"> 个人
										</label>
										<label class="radio-inline">
				  							<input type="radio" name="type" class="role1Btn" id="radio2" value="1"> 公司
										</label>
                					</td>
                				</tr>
                				<!-- 个人 -->
                				<tr class="even private">
                					<td style="text-align: right;">姓名<span class="fill-must">*</span></td>
                					<td class="even">
                						<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addName" name="name" placeholder="请输入账户姓名" required>
                					</td>
                				</tr>
                				<tr class="even private">
                					<td style="text-align: right;">手机号<span class="fill-must">*</span></td>
                            		<td class="even">
                                   		<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addPhone" name="tel" placeholder="请输入手机号" required data-rule-remote="${base}/checkNameUnique?category=AccountUserTel&where=and del=0" data-msg-remote="手机号码已存在" data-rule-mobile="true" data-msg-mobile="请输入正确格式" required/>
                            		</td>
                				</tr>
                				<tr class="even private">
                					<td style="text-align: right;">身份证号<span class="fill-must">*</span></td>
                					<td id="checkid" class="even">
                						<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addIdentity" name="identityid" placeholder="请输入身份证号" data-rule-idCard="true" data-msg-idCard="请输入正确格式" required/>
                					</td>
                				</tr>
                				<tr class="even private">
                					<td style="text-align: right;">所在地区<span class="fill-must">*</span></td>
                					<td class="even">
                						<select id="addProvince" name="provinceid" class="m-wrap span8" onchange="combox('addCity','City',$(this).val(),null,false)" required style="margin-top: 10px">
                						</select>
                						<select id="addCity" name="cityid" class="m-wrap span8" style="margin-top: 10px" required>
                						</select>
                					</td>
                				</tr>
                				
                				<!-- 公司 -->
                				<tr class="even company" style="display: none;">
                					<td style="text-align: right;">公司名称<span class="fill-must">*</span></td>
                            		<td class="even">
                                   		<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addName" name="Cname" placeholder="请输入公司名称" required />
                            		</td>
                				</tr>
                				<tr class="even company" style="display: none;">
                					<td style="text-align: right;">接收短信手机<span class="fill-must">*</span></td>
                            		<td class="even">
                                   		<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addPhone" name="Ctel" placeholder="请输入接收短信手机" required data-rule-remote="${base}/checkNameUnique?category=AccountUserTel&where=and del=0 and type=0" data-msg-remote="手机号码已存在" data-rule-mobile="true" data-msg-mobile="请输入正确格式"/>
                            		</td>
                				</tr>
                				<tr class="even company" style="display: none;">
                					<td style="text-align: right;">银行账号</td>
                            		<td id="checkbank" class="even">
                                   		<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addBankNum" name="bank_num" placeholder="请输入银行账号"/>
                            		</td>
                				</tr>
                				<tr class="even company" style="display: none;">
                					<td style="text-align: right;">开户行</td>
                            		<td class="even">
                                   		<input class="m-wrap span8" style="margin-top: 10px" type="text" id="addBankAcc" name="bank_account" placeholder="请输入开户行"/>
                            		</td>
                				</tr>
                				<tr class="even company" style="display: none;">
                					<td style="text-align: right;">说明</td>
                            		<td class="even">
                                   		<textarea class="form-control" rows="3" id="addComment" name="comment" placeholder=""></textarea>
                            		</td>
                				</tr>
                			</tbody>
                		</table>
                		</br>
                		<div class="controls controls-row" style="text-align: right;">
                        	<input type="button" value="保存" class="btn green" onclick="addEntity()"/>
                        	<input type="button" value="取消" class="btn green" onclick="fresh()" />
                    	</div>
                	</form>
                </div>
			</div>
		</div>
	</div>
	
<#include "bases/navhead.ftl">
<#include "bases/sidebar.ftl">

	<div class="page-container secMenu-content">    

     
        <div class="page-content">
     
            <div class="container-fluid">

                <div class="row-fluid">
                    <div class="span12">
                        <div class="portlet box green">
                            <div class="portlet-title">
                                <div class="caption"><i class="fa fa-cogs"></i>账户管理</div>
	                            <div class="tools">
	                                <a href="javascript:window.location.reload()" class="reload"></a>
	                            </div>
                            </div>
                            
                            <div class="portlet-body flip-scroll">
                            	<form id="searchform" action="<@spring.url '/account_user_general'></@spring.url>" method="POST">
                            		<input  type="hidden" id="currentpage" name="page" value="0" />
                            		<input  type="hidden" id="postactionorder" name="postactionorder" />
           
                            		<div class="controls controls-row">
      									<label for="tel" class="">手机号：</label>
                            			<input type="text" name="tel" class="form-control sheet-searchInput" value="<#if tel?exists>${tel}</#if>">
                            			
                            			<label for="carbrand">车牌号：</label>
										<input type="text" name="carbrand" class="form-control sheet-searchInput" value="<#if carbrand?exists>${carbrand}</#if>">
										
										<label for="name">账户类型：</label>
										<select name="Acctype" class="form-control sheet-searchInput" value="${Acctype!}">
											<option value="">===请选择===</option>
	                                    	<#if typeList??>
	                                			<#list typeList as tlist> 
	                                    			<option value="${tlist.getKey()}" <#if (Acctype!'')=="${tlist.getKey()}">selected="selected"</#if>><#if tlist.getValue()??>${tlist.getValue()}</#if></option>
	                                			</#list>
                                  			</#if>
										</select>
									
										<label for="name">所属公司：</label>
										<select name="account" class="form-control sheet-searchInput" value="${account!}">
											<option value="">===请选择===</option>
				  							<#if companyList??>
	                                			<#list companyList as clist> 
	                                    			<option value="${clist.getName()}" <#if (account!'')=="${clist.getKey()}">selected="selected"</#if>><#if clist.getName()??>${clist.getName()}</#if></option>
	                                			</#list>
                                  			</#if>
										</select>
                            		</div>
                            		
                            		<div class="controls controls-row"  style="margin-top: 20px">
                            			<label for="name">车型：</label>
                            			<select name="cartype" class="form-control sheet-searchInput" value="${cartype!}">
											<option value="">===请选择===</option>
											<#if cartypeList??>
												<#list cartypeList as ctlist>
													<option value="${ctlist.getKey()}" <#if (cartype!'')=="${ctlist.getKey()}">selected="selected"</#if>><#if ctlist.getName()??>${ctlist.getName()}</#if></option>
												</#list>
											</#if>
										</select>
										
										<label for="name">城市：</label>
                						<select name="cityid" class="form-control sheet-searchInput" value="${cityid!}">
                							<option value="">===请选择===</option>
                							<#if cityList??>
												<#list cityList as Clist>
													<option value="${Clist.getKey()}" <#if (cityid!'')=="${Clist.getKey()}">selected="selected"</#if>><#if Clist.getName()??>${Clist.getName()}</#if></option>
												</#list>
											</#if>
                						</select>
                						
                						<label for="name">车辆状态：</label>
                						<select name="carstatus" class="form-control sheet-searchInput" value="${carstatus!}">
                							<option value="">===请选择===</option>
                							<#if statusList??>
												<#list statusList as CSlist>
													<option value="${CSlist.getKey()}" <#if (carstatus!'')=="${CSlist.getKey()}">selected="selected"</#if>><#if CSlist.getValue()??>${CSlist.getValue()}</#if></option>
												</#list>
											</#if>
                						</select>
				
										<button type="submit" class="btn blue">搜索</button>
									</div>
                            	    
                            	    <div class="controls controls-row"  style="margin-top: 20px">
                            	        <button type="button" class="btn green"  onclick="showPopup('addDiv')"><i class="fa fa-plus"></i>新增账户</button>
                            	    </div>
                            	    
                            		   <table  class="table table-bordered table-hover table-striped table-condensed list-table">
	      								  <thead class="flip-content">
	        								<tr>
	          									<th><input type="checkbox" class="checkbox-length list-checkboxAll"></th>
	          									<th style="text-align: center;">账号</th>
	          									<th style="text-align: center;">所属个人</th>
	          									<th style="text-align: center;">所属公司</th>
	          									<th style="text-align: center;">账户类型</th>
	          									<th style="text-align: center;">车辆状态</th>
	          									<th style="text-align: center;">对应车牌</th>
	          									<th style="text-align: center;">所在地区</th>
	          									<th style="text-align: center;">当前套餐</th>
	          									<th class="am-obligate"></th>
	          									<th style="text-align: center;">操作人</th>
	          									<th style="text-align: center;">最后操作时间</th>
	        								</tr>
	      								 </thead>
	      								 <tbody>
	      								 <#list account_users as item>
	      								 
	      								 	<tr>
	      								 		<#if item?exists>
	      								 		<th><input value="${item.getId()}" name="checklist" type="checkbox" class="list-checkbox"></th>
	          									<td style="text-align: center;"><#if item.getAccount()?exists>${item.getAccount()}</#if></td>
	          									<td style="text-align: center;"><#if item.getType()==0 && item.getName()?exists>${item.getName()}<#else></#if></td>
	          									<td style="text-align: center;"><#if item.getCompany()??>${item.getCompany()}<#else></#if></td>
	          									<td style="text-align: center;"><#if item.getType()==0>个人<#else>公司</#if></td>
	          									<td style="text-align: center;"><#if item.getCarstatus()??>${item.getCarstatus()}</#if></td>
	          									<td style="text-align: center;"><#if item.getCarbrand()?exists>${item.getCarbrand()}</#if></td>
	          									<td style="text-align: center;"><#if item.getCity()?exists>${item.getCity()}</#if></td>
	          									<td style="text-align: center;" <#if item.getType()==1>onmouseover="showInfo($('#${item.getId()}').val());" class="am-comboBtn"</#if>><#if item.getType()==1><input id="${item.getId()}" value="${item.getId()}" type="hidden">显示详情<#elseif item.getConventional()?exists><a href="">${item.getConventional()}</a>-${item.getCartypename()}<#elseif item.getPack()?exists><a href="${base}/view_package_fare?task=edit&id=${item.getPackid()}">${item.getPack()}</a>-${item.getCartypename()}</#if></td>
	          									<#if item.getType()==1>
	          									<td class="am-obligate">
		      										<div class="am-comboContent">
			      										<div class="arrow"></div>
			      										<div class="arrow2"></div>   
			       										<div class="am-comboDetails">
			        									</div>
		        									</div>
	          									</td>
	          									<#else>
	          									<td class="am-obligate"></td>
	          									</#if>
	          									<td style="text-align: center;"><#if item.getOperator()?exists>${item.getOperator()}</#if></td>
	          									<td style="text-align: center;"><#if item.getOperdate()?exists>${item.getOperdate()}</#if></td>
	          									</#if>
	      								 	</tr>
	      								 </#list>
	      								  </tbody>
	      							</table>
	      							<div class="controls controls-row">
                                    	<div id="Pagination" class="pagination"></div>
                            	</form>
                            </div>
                        </div>
                    </div>
                </div>
                
            </div>
            
        </div>
        
     </div>
     
</body>
